/*
 * Copyright 2025 The JA-SIG Collaborative. All rights reserved.
 * distributed with this file and available online at
 */
package com.lap.auth.adapter.driving.query.menu.repository;

import com.lap.auth.adapter.driving.query.menu.MenuViewLogQueryConverter;
import com.lap.auth.adapter.driving.query.menu.mapper.MenuViewLogQueryMapper;
import com.lap.auth.adapter.driving.query.menu.po.MenuViewLogQueryPo;
import com.lap.auth.application.menu.dto.MenuViewLogDto;
import com.lap.auth.application.menu.dto.QueryMenuViewLogPageQuery;
import com.lap.auth.application.menu.repository.MenuViewLogQueryRepository;
import com.lap.framework.common.dto.page.PageResponse;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Repository;

@RequiredArgsConstructor
@Repository
public class MenuViewLogQueryRepositoryImpl implements MenuViewLogQueryRepository {

  private final MenuViewLogQueryConverter menuViewLogQueryConverter;
  private final MenuViewLogQueryMapper menuViewLogQueryMapper;

  @Override
  public PageResponse<MenuViewLogDto> findByConditionPaged(QueryMenuViewLogPageQuery query) {
    long count = menuViewLogQueryMapper.countPageByCondition(query);
    if (count == 0L) {
      return PageResponse.ok(count);
    }
    List<MenuViewLogQueryPo> list = menuViewLogQueryMapper.selectPageByCondition(query);
    return PageResponse.ok(menuViewLogQueryConverter.toDtoList(list), count);
  }
}
